package com.xbongbong.pro.enums.fund.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * 账期规则条件类型枚举
 * @author zcp
 * @version v1.0
 * @since v1.0
 */
@Getter
public enum PeriodTypeEnum {
    /**
     * 账期规则条件类型：0无账期（未选择），1每周，2每月，3每年，4应收生成后
     */
    NONE(0,"none", "enum.periodType.name.none"),
    WEEK(1,"week", "enum.periodType.name.week"),
    MONTH(2,"month", "enum.periodType.name.month"),
    YEAR(3,"year", "enum.periodType.name.year"),
    DAY_AFTER(4,"day", "enum.periodType.name.dayAfter"),
    ;

    /**
     * 模式code
     */
    private Integer code;

    /**
     * 模式alias
     */
    private String alias;

    /**
     * 模式名称
     */
    private String name;


    PeriodTypeEnum(Integer code, String alias, String name){
        this.code = code;
        this.alias = alias;
        this.name = name;
    }
    /**
     * 根据code获取枚举
     * @param code
     * @return com.xbongbong.pro.enums.fund.enums.PeriodTypeEnum
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    public static PeriodTypeEnum getByCode(Integer code){
        for (PeriodTypeEnum cache : values()) {
            if (Objects.equals(cache.code, code)) {
                return cache;
            }
        }
        return null;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public String getI18nName() {
        return name;
    }
}
